package com.tar.system.sys.dao.impl;

import org.springframework.stereotype.Repository;

import com.tar.commons.hibernate.HibernateDao;
import com.tar.system.sys.dao.HibernateAccountDao;
import com.tar.system.sys.model.Account;

@Repository
public class HibernateAccountDaoImpl extends HibernateDao<Account> implements HibernateAccountDao {
	

	@Override
	public void outMoney(String out, Double money) {
		Account account = this.findUnique("select t from Account t where t.name=?", out) ;
		account.setMoney(account.getMoney() - money);
		
		this.update(account);
		
	}

	@Override
	public void inMoney(String in, Double money) {
		Account account = this.findUnique("select t from Account t where t.name=?", in) ;
		account.setMoney(account.getMoney() + money);
		
		this.update(account);
	}

	@Override
	public void initData() {
		Account a1 = new Account() ;
		a1.setName("aaa");
		a1.setMoney(1000d);
		
		Account a2 = new Account() ;
		a2.setName("bbb");
		a2.setMoney(1000d);
		
		this.save(a1);
		this.save(a2);
		
	}

}
